//
//  BoxCostHeadView.m
//  XLDoctor
//
//  Created by longma on 2018/10/8.
//  Copyright © 2018年 XLH. All rights reserved.
//

#import "GradientRampView.h"
#import "GradientRampItemView.h"

@implementation GradientRampView

- (void)awakeFromNib{
    [super  awakeFromNib];
    
    
}
- (void)setTitleArray:(NSArray *)titleArray {
    if(_titleArray.count){
        return;
    }
    _titleArray = titleArray;
    if(self.type == 5){
        self.colorArray = @[@"#FFF2EF",@"#FDDBDB",@"#F5A7A7",@"#ED7263",@"#C93D2B"];
    }
    for (int i = 0; i<titleArray.count; i++) {
        GradientRampItemView *itemView = [GradientRampItemView mj_loadNibWithOwner:self];
        itemView.autoresizingMask = UIViewAutoresizingNone;
        NSString* s1= titleArray[i];
        itemView.labTitle.mj_localizable = s1;

        if(self.type == DetectionItemTypeGout){
            itemView.viewLine.backgroundColor = [HealthHelper getHBColorWithGradeStr:titleArray[i]];
        }
        if(self.type == DetectionItemTypeHB){
            itemView.viewLine.backgroundColor = [HealthHelper getHBColorWithGradeStr:titleArray[i]];
        }
        if(self.type == DetectionItemTypeGlu){
            itemView.viewLine.backgroundColor = [HealthHelper getGluColorWithGradeStr:titleArray[i]];
        }
        if(self.type == DetectionItemTypeTC){
            itemView.viewLine.backgroundColor = [HealthHelper getTCColorWithGradeStr:titleArray[i]];
        }
        
        if(i == 0){
            itemView.leftCornerRadius = true;
        }
        if(i == titleArray.count - 1){
            itemView.rightCornerRadius = true;
        }
        //动态添加
        [self.stackView addArrangedSubview:itemView];
    }
    
}
- (void)layoutSubviews{
    [super layoutSubviews];
    
    CGFloat w = self.mj_width/self.titleArray.count;
    self.viewCircleBgW.constant = w;
    self.viewCircleBgLeft.constant = self.index *w;
    
}
- (void)setIndex:(NSInteger)index {
    _index = index;
    
    UIColor *color = [HealthHelper getTCColorWithGradeStr:self.titleArray[index]];
    if(self.type == DetectionItemTypeGout){
        color = [HealthHelper getHBColorWithGradeStr:self.titleArray[index]];
    }
    if(self.type == DetectionItemTypeHB){
        color = [HealthHelper getHBColorWithGradeStr:self.titleArray[index]];
    }
    if(self.type == DetectionItemTypeGlu){
        color = [HealthHelper getGluColorWithGradeStr:self.titleArray[index]];
    }
    if(self.type == DetectionItemTypeTC){
        color = [HealthHelper getTCColorWithGradeStr:self.titleArray[index]];
    }

    [self.viewCircle mj_borderColor:color width:2];
    [self layoutSubviews];
    

}

@end
